package com.example.hqpatrol.common.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.LongSerializationPolicy;
import com.google.gson.reflect.TypeToken;

import java.util.Map;

public class GsonUtil {

    private static Gson gson;

    public static Gson getInstance() {
        if(gson == null){
            gson = new GsonBuilder()
                    .registerTypeAdapter(new TypeToken<Map<String, Object>>() {}.getType(), new GsonDataTypeAdaptor())
                    .disableHtmlEscaping()
                    .create();
        }
        return gson;
    }

    public static Map<String, Object> beanToMap(Object bean) {
        return getInstance().fromJson(getInstance().toJson(bean), new TypeToken<Map<String, Object>>() {}.getType());
    }

}
